<?php 
function identifier_utilisateur($login,$mot_passe){
   global $connexion_serveur; 
   $sql="SELECT * FROM utilisateurs WHERE login='$login' AND mot_passe='$mot_passe'";
   $requete_sql = mysqli_query($connexion_serveur,$sql);
   $resultat = mysqli_fetch_assoc($requete_sql);
   
   if(!empty($resultat['id'])){
       $_SESSION["utilisateur_id"]=$resultat["id"];
       $message_action["texte"] = "L'identification a réussie !";
        $message_action["css_class"] = "alert-success";
    }
    else {
        $message_action["texte"] = "L'identification a échouée !";
        $message_action["css_class"] = "alert-danger";
    }
    return $message_action;
}

function proteger_page($variable_controle, $chemin) {
    
    session_start();
    
    if(!isset($_SESSION[$variable_controle])) {
        session_destroy();
        
        header("Location: $chemin");
    }
}

function deconnexion() {
    session_destroy();
    
    $message_action["texte"] = "La déconnexion a réussie !";
    $message_action["css_class"] = "alert-success";
    
    $message_action = serialize($message_action);
    
    header("Location: $chemin?message_action=$message_action");
}
